#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

long long x[100000] = { 0 };
long long y[100000] = { 0 };

void Test1()
{
    int n, m;
    //long long c;
    cin >> n >> m;


    vector<vector<long long>> v(n, vector<long long>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%lld", &v[i][j]);
            x[i] += v[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            y[i] += v[j][i];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cout << (x[i] + y[j] - v[i][j]) << " ";
        }
        cout << endl;
    }
}


int main()
{

	Test1();
    /*long long a;
    scanf("ll", &a);
    cout << a;*/


	return 0;
}